﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using LJLNet.Application;

namespace LJLNet.Thread
{
    public class AcceptThread : BaseThread
    {
        private Socket mServerSocket { get; set; }
        private Application.Application mApplication;

        public AcceptThread(Application.Application application, Socket serverSocket)
        {
            mApplication = application;
            mServerSocket = serverSocket;
        }

        protected override void Run()
        {
            if (mThread != null && mServerSocket != null)
            {
                while (true)
                {
                    Socket clientSocket = mServerSocket.Accept();//暂停当前线程，知道接收到客户端发来的连接请求；当接收到客户端的连接请求后，在本地服务器创建一个socket与客户端连接，并返回出来  
                    Console.WriteLine("有个客户端连接进来");
                    mApplication.CreatePeer(clientSocket);
                }
            }
        }
    }
}
